/*
 * Copyright (c) [2012] - [2017] Red Hat, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Red Hat, Inc. - initial API and implementation
 */
package com.codenvy.ldap.sync;

import com.google.inject.Inject;
import com.google.inject.persist.Transactional;
import java.util.List;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.persistence.EntityManager;

/**
 * Helps to make db requests.
 *
 * @author Yevhenii Voevodin
 */
@Singleton
public class DBHelper {

  @Inject private Provider<EntityManager> emProvider;

  /**
   * Executes native query and returns execution result.
   *
   * @param nativeQuery query to execute
   * @return execution result
   */
  @Transactional
  public List executeNativeQuery(String nativeQuery) {
    return emProvider.get().createNativeQuery(nativeQuery).getResultList();
  }
}
